<?php

namespace app\common\model;;

class TokenModel2 extends BaseModel
{
	protected $table = 'tp_token2';

	/*
	设置token
	 */
	public function setToken($uid){
		$token = md5(uniqid().$uid.microtime());
		$re = $this->where('uid',$uid)->find();
		if ($re) {
			$res = $this->where('uid',$uid)->update([
				'token' =>$token,
				'status'=>1
			]);
		} else {
			$res = $this->insert([
				'uid' => $uid,
				'status'=>1,
				'token' =>$token
			]);
		}
		if ($res) {
			return $token;
		} else {
			return false;
		}
	}

	/*
	token 验证
	 */
	public function veriToken($uid,$token){
		$res = $this->where('uid',$uid)->where('token',$token)->where('status',1)->find();
		return $res;
	}
}